﻿namespace QiangPiao
{
    using System;
    using System.Text;
    using System.Windows.Forms;

    public class ComboBoxEx : ComboBox
    {
        public static string GetChineseSpell(string strText)
        {
            int length = strText.Length;
            string str = "";
            for (int i = 0; i < length; i++)
            {
                str = str + getSpell(strText.Substring(i, 1));
            }
            return str;
        }

        public static string getSpell(string cnChar)
        {
            byte[] bytes = Encoding.Default.GetBytes(cnChar);
            if (bytes.Length > 1)
            {
                int num = bytes[0];
                int num2 = bytes[1];
                int num3 = (num << 8) + num2;
                int[] numArray = new int[] { 
                    0xb0a1, 0xb0c5, 0xb2c1, 0xb4ee, 0xb6ea, 0xb7a2, 0xb8c1, 0xb9fe, 0xbbf7, 0xbbf7, 0xbfa6, 0xc0ac, 0xc2e8, 0xc4c3, 0xc5b6, 0xc5be, 
                    0xc6da, 0xc8bb, 0xc8f6, 0xcbfa, 0xcdda, 0xcdda, 0xcdda, 0xcef4, 0xd1b9, 0xd4d1
                 };
                for (int i = 0; i < 0x1a; i++)
                {
                    int num5 = 0xd7fa;
                    if (i != 0x19)
                    {
                        num5 = numArray[i + 1];
                    }
                    if ((numArray[i] <= num3) && (num3 < num5))
                    {
                        return Encoding.Default.GetString(new byte[] { (byte) (0x41 + i) });
                    }
                }
                return "*";
            }
            return cnChar;
        }

        protected override void OnTextUpdate(EventArgs e)
        {
            BindingSource dataSource = base.DataSource as BindingSource;
            dataSource.Filter = string.Format("Text like '{0}%' or SID like '{0}%'", this.Text);
            base.DroppedDown = true;
            this.Cursor = Cursors.Default;
            base.OnTextUpdate(e);
        }
    }
}

